<template>
  <div class="app-container">
    <el-card class="cardtop">
      <h3 class="title-left">员工详情</h3>
      <el-divider style="border-width: thin"></el-divider>
      <el-button @click="returnUp" class="retu">返回</el-button>
      <div class="info">
        <el-image
          class="img"
          :src="url"
          :fit="fit"></el-image>
        <span style="padding-left: 93px;font-size: 22px;font-weight: lighter">{{name}}</span>
        <div class="infomid">
          <span>{{statu}}</span>
          <el-divider direction="vertical"></el-divider>
          <span>{{type}}</span>
          <el-divider direction="vertical"></el-divider>
          <span>{{company}}</span>
          <el-divider direction="vertical"></el-divider>
          <span>部门</span>
        </div>
        <div class="infobom">
          <i class="el-icon-phone-outline"/>{{phone}}
          &nbsp;&nbsp;&nbsp;&nbsp;
          <i class="el-icon-message"/>{{email}}
        </div>
        <el-tag type="success" style="margin-left: 110px">{{statu}}</el-tag>

      </div>

    </el-card>

    <el-card class="cardleft">
      <h3 class="title-left">员工信息</h3>
      <ul class="ulclass">
        <li @click="getInfo(1)">
          <a class="tab" :class="{ 'active-tab': activeTab === 1 }">个人信息</a>
          <div class="arrow-container" :class="{ 'show-arrow': activeTab === 1 }">
            <i class="el-icon-right arrow-right"></i>
          </div>
        </li>
        <li @click="getInfo(2)">
          <a class="tab" :class="{ 'active-tab': activeTab === 2 }">工作信息</a>
          <div class="arrow-container" :class="{ 'show-arrow': activeTab === 2 }">
            <i class="el-icon-right arrow-right"></i>
          </div>
        </li>
        <li @click="getInfo(3)">
          <a class="tab" :class="{ 'active-tab': activeTab === 3 }">教育经历</a>
          <div class="arrow-container" :class="{ 'show-arrow': activeTab === 3 }">
            <i class="el-icon-right arrow-right"></i>
          </div>
        </li>
        <li @click="getInfo(4)">
          <a class="tab" :class="{ 'active-tab': activeTab === 4 }">合同信息</a>
          <div class="arrow-container" :class="{ 'show-arrow': activeTab === 4 }">
            <i class="el-icon-right arrow-right"></i>
          </div>
        </li>
      </ul>
    </el-card>

    <el-card class="cardright">
      <el-row style="margin: 20px 0 20px 20px">
        <el-col :span="3"><h3 class="title-left top1">基础信息</h3></el-col>
        <el-col :span="20"><el-divider style="border-width: thin" class="top2"></el-divider></el-col>
        <el-col :span="1"><a class="top3">编辑</a></el-col>
      </el-row>

      <!-- 个人信息描述列表-->
      <el-descriptions class="right_info" column="2" v-show="flag===1">
        <el-descriptions-item label="姓名" style="width: 100px">{{name}}</el-descriptions-item>
        <el-descriptions-item label="年龄">{{age}}岁</el-descriptions-item>
        <el-descriptions-item label="性别" style="margin-top: 20px">{{gender}}</el-descriptions-item>
        <el-descriptions-item label="民族" style="margin-top: 20px">{{native}}</el-descriptions-item>
        <el-descriptions-item label="身份证号" style="margin-top: 20px">{{idno}}</el-descriptions-item>
        <el-descriptions-item label="手机号">{{phone}}</el-descriptions-item>
        <el-descriptions-item label="员工状态">{{statu}}</el-descriptions-item>
        <el-descriptions-item label="员工类型">{{type}}</el-descriptions-item>
        <el-descriptions-item label="政治面貌">{{political}}</el-descriptions-item>
        <el-descriptions-item label="学历">{{education}}</el-descriptions-item>
        <el-descriptions-item label="籍贯">{{native}}</el-descriptions-item>
        <el-descriptions-item label="微信">{{wx}}</el-descriptions-item>
        <el-descriptions-item label="qq">{{qq}}</el-descriptions-item>
        <el-descriptions-item label="备注">
          <el-tag size="small">学校</el-tag>
        </el-descriptions-item>
      </el-descriptions>
      <!-- 工作信息描述列表-->
      <el-descriptions class="right_info" column="2" v-show="flag===2">
        <el-descriptions-item label="员工编号" style="width: 100px">{{eno}}</el-descriptions-item>
        <el-descriptions-item label="部门">{{depart}}</el-descriptions-item>
        <el-descriptions-item label="职位" style="margin-top: 20px">{{position}}</el-descriptions-item>
        <el-descriptions-item label="职级" style="margin-top: 20px">{{level}}</el-descriptions-item>
        <el-descriptions-item label="工作地点" style="margin-top: 20px">{{place}}</el-descriptions-item>
        <el-descriptions-item label="上级负责人">{{superLeader}}</el-descriptions-item>
        <el-descriptions-item label="入职日期">{{enterDate}}</el-descriptions-item>
      </el-descriptions>

      <!-- 教育经历描述列表-->
      <el-descriptions class="right_info" column="2" v-show="flag===3">
        <el-descriptions-item label="毕业院校" style="width: 100px">{{eduUniversity}}</el-descriptions-item>
        <el-descriptions-item label="入学日期">{{eduEnter}}</el-descriptions-item>
        <el-descriptions-item label="毕业日期" style="margin-top: 20px">{{eduEnd}}</el-descriptions-item>
        <el-descriptions-item label="学制" style="margin-top: 20px">{{eduDuring}}年</el-descriptions-item>
        <el-descriptions-item label="状态" style="margin-top: 20px">{{eduStatus}}</el-descriptions-item>
        <el-descriptions-item label="照片">{{eduPicture}}</el-descriptions-item>
        <el-descriptions-item label="学历">{{eduEducation}}</el-descriptions-item>
        <el-descriptions-item label="教育类型">{{eduType}}</el-descriptions-item>
      </el-descriptions>

      <!-- 合同信息描述列表-->
      <el-descriptions class="right_info" column="2" v-show="flag===4">
        <el-descriptions-item label="合同编号" style="width: 100px">{{cno}}</el-descriptions-item>
        <el-descriptions-item label="合同类型">{{conType}}</el-descriptions-item>
        <el-descriptions-item label="合同状态" style="margin-top: 20px">{{conStatus}}</el-descriptions-item>
        <el-descriptions-item label="合同公司" style="margin-top: 20px">{{conCompany}}</el-descriptions-item>
        <el-descriptions-item label="合同开始时间" style="margin-top: 20px">{{conStart}}</el-descriptions-item>
        <el-descriptions-item label="合同结束时间">{{conEnd}}</el-descriptions-item>
        <el-descriptions-item label="合同签订时间">{{conSgin}}</el-descriptions-item>
        <el-descriptions-item label="负责人">{{conHeader}}</el-descriptions-item>
        <el-descriptions-item label="合同有效期">{{conDeadline}}年</el-descriptions-item>
        <el-descriptions-item label="附件">{{conFile}}</el-descriptions-item>
        <el-descriptions-item label="备注">{{conCom}}</el-descriptions-item>
      </el-descriptions>

    </el-card>

  </div>
</template>
<style>
.active-tab {
  color: blue;
}
.arrow-right {
  color: blue;
  font-weight: bold;
  margin-left: 105px;
}
.arrow-container {
  display: none; /* 默认隐藏箭头容器 */
}
.show-arrow {
  display: inline-block; /* 显示箭头容器 */
}
.title-left{
  position: relative;
  padding-left: 13px;
  margin: 2px 0
}
.title-left:before{
  content: "";
  background-color: #3796EC;
  width: 5px;
  height: 17px;
  position: absolute;
  left: 5px;
  top: 45%;
  margin: -8px;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
}
.cardtop{
  height: 400px;
  margin-bottom: 20px;
}
.cardleft{
  width: 250px;
  height: 250px;
  margin-right: 15px;
  margin-left: 25px;
  float: left;
}
.cardright{
  float: left;
  width: 950px;
  height: 500px;
}
.ulclass{
  margin-top: 35px;
  margin-left: -25px;
}
.ulclass li{
  margin: 20px 0px;
}
.ulclass li:hover{
  color: dodgerblue;
}
.top1{
  position: relative;
  top: 16px;
}
.top2{
  position: relative;
  left: -10px;
}
.top3{
  position: relative;
  top: 16px;
  left: 3px;
  color:dodgerblue;
}
.retu{
  position: relative;
  top: -10px;
}
.info{
  width: 400px;
  height: 200px;
  position: relative;
  left: 450px;
}
.infomid{
  margin-top: 9px;
  margin-left: -10px;
  font-size: 13px;
  color: rgba(187, 189, 192, 0.92);
}
.infobom{
  margin-top: 9px;
  margin-left: -10px;
  margin-bottom: 10px;
  font-size: 13px;
  color: rgba(187, 189, 192, 0.92);
  letter-spacing: 2px;
}
.img{
  width: 100px;
  height: 100px;
  border-radius: 50px;
  display: block;
  margin-left: 85px;
  margin-bottom: 8px;
}
.right_info{
  margin-top: 50px;
  margin-left: 100px;
  font-size: 16px;
}
</style>
<script>
import Link from '@/layout/components/Sidebar/Link'
import { getEmplyee } from '@/api/system/emplyee'
export default {
  dicts: ['sys_education', 'sys_emplyee_status', 'sys_political',
    'sys_emplyee_type', 'sys_user_sex','sys_contract_status',
    'sys_contract_type','sys_education',
    'sys_education_status','sys_education_type'
  ],
  name: "EmpDetail",
  components: { Link },
  data() {
    return {
      fits: ['fill', 'contain', 'cover', 'none', 'scale-down'],
      url: '',
      activeTab: 1,
      //基本个人信息
      avator:'',
      eno:'',
      name:'',
      age:'',
      gender:'',
      native:'',
      nation:'',
      idno:'',
      wx:'',
      qq:'',
      political:'',
      education:'',
      statu:'',
      type:'',
      company:'',
      dept:'',
      phone:'',
      email:'',
      //合同信息
      cno: '',
      conType: '',
      conStatus: '',
      conCompany: '',
      conStart: '',
      conEnd: '',
      conSgin: '',
      conHeader: '',
      conDeadline: '',
      conFile: '',
      conCom: '',
      //工作信息
      depart: '',
      position: '',
      level: '',
      place: '',
      superLeader: '',
      enterDate: '',
      //学历信息
      eduUniversity: '',
      eduEnter: '',
      eduEnd: '',
      eduDuring: '',
      eduStatus: '',
      eduPicture: '',
      eduEducation: '',
      eduType: '',
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      tabPosition: 'left',
      // 总条数
      total: 0,
      // 合同工表格数据
      emplyeeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //显示描述列表
      flag:1,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cno: null,
        name: null,
        type: null,
        education: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        gender: [
          { required: true, message: "性别：1男，2女，3其他不能为空", trigger: "change" }
        ],
        email: [
          { required: true, message: "邮箱不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    const eno = this.$route.params && this.$route.params.eno;
    console.log(eno)
    this.getEmpInfo(eno);
  },
  methods: {
    getInfo(index){
      console.log(index);
      this.loading = true;
      this.flag = index;
      this.activeTab = index;
      //个人信息
      if(index===1){
        getEmplyee(this.eno).then(res => {
          this.name = res.data.name;
          this.age = res.data.age;
          // this.dept = res.data.name;
          this.phone = res.data.phone;
          this.email = res.data.email;
          this.native = res.data.nativePlace;
          this.nation = res.data.nation;
          this.wx = res.data.wechat;
          this.qq = res.data.qq;
          this.idno = res.data.idno;
          this.qq = res.data.qq;
          //性别赋值
          for (let i = 0; i < 3; i++) {
            let obj = this.dict.type.sys_user_sex[i];
            console.log(obj);
            if(obj.value === res.data.gender) {
              this.gender = obj.label;
              break;
            }
          }
          //员工状态赋值
          for (let i = 0; i < 2; i++) {
            let obj = this.dict.type.sys_emplyee_status[i];
            if(obj.value === res.data.status) {
              this.statu = obj.label;
              break;
            }
          }
          //员工类型赋值
          for (let i = 0; i < 4; i++) {
            let obj = this.dict.type.sys_emplyee_type[i];
            if(obj.value === res.data.type) {
              this.type = obj.label;
              break;
            }
          }
          //公司赋值
          this.company = res.data.contract.company;
          //政治面貌
          for (let i = 0; i < 4; i++) {
            let obj = this.dict.type.sys_political[i];
            if(obj.label === res.data.political) {
              this.political = obj.value;
              break;
            }
          }
          //学历赋值
          for (let i = 0; i < 5; i++) {
            let obj = this.dict.type.sys_education[i];
            if(obj.value === res.data.education) {
              this.education = obj.label;
              break;
            }
          }
          this.loading = false;
        });
      }
      //工作信息
      else if(index===2){
        getEmplyee(this.eno).then(res => {
          this.depart = res.data.workinfo.depart;
          this.level = res.data.workinfo.level;
          this.place = res.data.workinfo.place;
          this.position = res.data.workinfo.position;
          this.superLeader = res.data.workinfo.superLeader;
          this.enterDate = res.data.workinfo.enterDate;
          this.superLeader = res.data.workinfo.superLeader;
        });
      }
      //教育经历
      else if(index===3){
        getEmplyee(this.eno).then(res => {
          this.eduUniversity = res.data.educat.university;
          this.eduDuring = res.data.educat.during;
          this.eduEnd = res.data.educat.endDate;
          this.eduEnter = res.data.educat.enterDate;
          this.eduEducation = res.data.educat.superLeader;
          //教育类型
          for (let i = 0; i < 3; i++) {
            let obj = this.dict.type.sys_education_type[i];
            if(obj.value === res.data.educat.type) {
              this.eduType = obj.label;
              break;
            }
          }
          //毕业状态
          for (let i = 0; i < 2; i++) {
            console.log(this.dict.type.sys_education_status[i]);
            let obj = this.dict.type.sys_education_status[i];
            if(obj.value === res.data.educat.status) {
              this.eduStatus = obj.label;
              break;
            }
          }
          //学历
          for (let i = 0; i < 5; i++) {
            let obj = this.dict.type.sys_education[i];
            if(obj.value === res.data.educat.education) {
              this.eduEducation = obj.label;
              break;
            }
          }
          this.eduType = res.data.educat.enterDate;
          this.superLeader = res.data.educat.superLeader;
        });
      }
      //合同信息
      else if(index===4){
        getEmplyee(this.eno).then(res => {
          console.log(res.data);
          this.cno = res.data.contract.cno;
          this.conCompany = res.data.contract.company;
          this.conHeader = res.data.contract.header;
          this.conDeadline = res.data.contract.deadline;
          this.conStart = res.data.contract.startDate;
          this.conSgin = res.data.contract.sginDate;
          this.conEnd = res.data.contract.endDate;
          //合同类型
          for (let i = 0; i < 4; i++) {
            let obj = this.dict.type.sys_contract_type[i];
            if(obj.value === res.data.contract.type) {
              this.conType = obj.label;
              break;
            }
          }
          //合同状态
          for (let i = 0; i < 2; i++) {
            console.log(this.dict.type.sys_contract_status[i]);
            let obj = this.dict.type.sys_contract_status[i];
            if(obj.value === res.data.contract.status) {
              this.conStatus = obj.label;
              break;
            }
          }
        });
      }
      this.loading = false;
    },
    /** 查询员工信息 */
    getEmpInfo(eno) {
      this.loading = true;
      getEmplyee(eno).then(res => {
        console.log(res);
        this.eno = eno;
        this.name = res.data.name;
        this.url = res.data.avator;
        // this.dept = res.data.name;
        this.phone = res.data.phone;
        this.email = res.data.email;
        //员工状态赋值
        for (let i = 0; i < 2; i++) {
          let obj = this.dict.type.sys_emplyee_status[i];
          if(obj.value === res.data.status) {
            this.statu = obj.label;
            break;
          }
        }
        //员工类型赋值
        for (let i = 0; i < 4; i++) {
          let obj = this.dict.type.sys_emplyee_type[i];
          if(obj.value === res.data.type) {
            this.type = obj.label;
            break;
          }
        }
        //公司赋值
        this.company = res.data.contract.company;
        this.getInfo(1);
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        eno: null,
        cno: null,
        name: null,
        age: null,
        gender: null,
        phone: null,
        email: null,
        nation: null,
        idno: null,
        status: null,
        type: null,
        education: null,
        political: null,
        nativePlace: null,
        wechat: null,
        qq: null
      };
      this.resetForm("form");
    },
    returnUp(){
      const obj = { path: "/person/sgang/emplyee" };
      this.$tab.closeOpenPage(obj);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.eno != null) {
            updateEmplyee(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEmplyee(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
